package com.atguigu.pratice;

import java.util.Scanner;

public class FindTheBiggestSubstringInTwoSring {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        String s1=scanner.next();
        String s2=scanner.next();
        //特殊情况，短的字符串是长的字符串的一部分
        if(s1.contains(s2)){
            System.out.println(s2);
            return;
        }else if(s2.contains(s1)){
            System.out.println(s1);
            return;
        }
        //三层遍历？
        int max=0;
        String minString=null;
        String maxString=null;
        //先找到短串是哪个，方便进行遍历
        if(s1.length()<s2.length()){
            minString=s1;
            maxString=s2;
        }else{
            maxString=s1;
            minString=s2;
        }
        StringBuilder sb=new StringBuilder();
        for(int i=0;i<minString.length();i++){
            for(int j=0;j<maxString.length();j++){
                int tmp=0;
                int left=i;
                int right=j;
                while(left<minString.length()&&right<maxString.length()&&minString.charAt(left)==maxString.charAt(right)){
                    sb.append(minString.charAt(left));
                    tmp++;
                    left++;
                    right++;
                }
                if(tmp>max){
                    max=tmp;
                }
            }
        }
        for(int i=0;i<minString.length();i++){
            for(int j=0;j<maxString.length();j++){
                sb=new StringBuilder();
                int left=i;
                int right=j;
                while(left<minString.length()&&right<maxString.length()&&minString.charAt(left)==maxString.charAt(right)){
                    sb.append(minString.charAt(left));
                    left++;
                    right++;
                    if(sb.length()==max){
                        System.out.println(sb.toString());
                        return;
                    }
                }
            }
        }
    }
}
